# -*- coding: utf-8 -*-
# @Time : 2023/7/17 22:22
# @Author : TH
# Description:日志封装类
import logging
import time
import os
from config import pathManage


# 封装自己的logging
class MyLogger:
    def __init__(self):
        self._logName = os.path.join(pathManage.LOG_DIR, "{}.log".format(time.strftime("%Y%m%d")))
        self._logger = logging.getLogger("logger")
        self._logger.setLevel(logging.DEBUG)
        self._formatter = logging.Formatter('[%(asctime)s][%(filename)s %(lineno)d][%(levelname)s]:%(message)s')
        self._streamHandler = logging.StreamHandler()
        self._fileHandler = logging.FileHandler(self._logName, mode='a', encoding="utf-8")
        self._streamHandler.setFormatter(self._formatter)
        self._fileHandler.setFormatter(self._formatter)
        self._logger.addHandler(self._streamHandler)
        self._logger.addHandler(self._fileHandler)

    # 获取logger日志记录器
    def get_logger(self):
        return self._logger


logger = MyLogger().get_logger()  # 记录定义一个logger对象，让其他文件只能获取该logger对象


if __name__ == '__main__':
    logger.info('xxxx')